package com.nuanshui.heatedloan.credit.service;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.framework.lang.DateUtil;
import com.nuanshui.heatedloan.constant.ServiceConstant;
import com.nuanshui.heatedloan.credit.dal.mapper.ZeroDayInfoMapper;
import com.nuanshui.heatedloan.credit.facade.ZeroDayInfoService;
import com.nuanshui.heatedloan.credit.model.ZeroDayInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * Created by wangxw on 2017/7/15.
 */

@Service(ServiceConstant.ZERODAYINFOSERVICE)
@Transactional(readOnly=true,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER)
public class ZeroDayInfoServiceImpl   implements ZeroDayInfoService {

    @Autowired
    private ZeroDayInfoMapper zeroDayInfoMapper;

    @Override
    public ZeroDayInfo getZeroDayInfoByUserIdAndType(String userId, int type) {
        return zeroDayInfoMapper.getZeroDayInfoByUserIdAndType(userId,type);
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER,propagation = Propagation.REQUIRES_NEW)
    public void updateZeroDayInfoByUserIdAndType(String userId,int type,int day) {
        Date date=DateUtil.getDateByPattern(new Date(),"yyyy-MM-dd");
        zeroDayInfoMapper.updateZeroDayInfoByUserIdAndType(userId,type, day,date);
    }

    @Override
    @Transactional(readOnly=false,value= TransactionManagerType.CREDIT_TRANSACTION_MANAGER,propagation = Propagation.REQUIRES_NEW)
    public void insertZeroDayInfoByUserIdAndType(ZeroDayInfo zeroDayInfo){
        Date date=DateUtil.getDateByPattern(new Date(),"yyyy-MM-dd");
        zeroDayInfo.setZeroDayStartDate(date);
        zeroDayInfoMapper.insertZeroDayInfoByUserIdAndType(zeroDayInfo);
    }

    public static void main(String[] args) {
        System.out.println(DateUtil.getDateByPattern(new Date(),"yyyy-MM-dd HH:mm:ss"));
    }

}
